package Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class TT2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        ArrayList<ArrayList<Integer>> list = new ArrayList<>();
        int itemRight = 0;
        int itemLeft = 0;
        boolean flag = false;
        for (int i = 0; i < size; i++) {
            int left = sc.nextInt();
            int right = sc.nextInt();
            flag = false;
            //第一次进入
            if (i == 0) {
                itemLeft = left;
                itemRight = right;
            }
            if (left <= itemRight) {
                itemRight = Math.max(right, itemRight);
            } else {
                ArrayList<Integer> item = new ArrayList<>();
                item.add(itemLeft);
                item.add(itemRight);
                list.add(item);
                itemLeft = left;
                itemRight = right;
                flag = true;
            }
        }
        ArrayList<Integer> item = new ArrayList<>();
        item.add(itemLeft);
        item.add(itemRight);
        list.add(item);
        System.out.println(Arrays.toString(list.toArray()));
    }
}
